export const toTree = (data: any) => {
	const fixedArr = data.map((item: any) => {
		return {
			label: item.name,
			id: item.iD,
			visiblity: item.visiblity,
			index: item.index,
			parentIndex: item.parentIndex,
			color: item.color ? item.color.replace('RGB', 'rgb') : 'rgb(255, 255, 255)',
			style: item.style ? item.style : 0,
			type: item.type,
		}
		// delete item.children;
	})
	const map: any = {}
	fixedArr.forEach(function (item: any) {
		map[item.index] = item
	})
	const val: any = []
	fixedArr.forEach(function (item: any) {
		const parent = map[item.parentIndex]
		if (parent) {
			;(parent.children || (parent.children = [])).push(item)
		} else {
			val.push(item)
		}
	})
	return val
}
